#ifndef SHARED_H_
#define SHARED_H_

#define ALWAYS 1
#define MSG_SIZE 255
#define BORRA_BUFFER    while(getchar()!= '\n');
#define SEC_TIMEOUT 0
#define MSEC_TIMEOUT 200
#define TCP_HOST "localhost"
#define TCP_PORT "12345"
#define FIFO_INIT "/tmp/conn_req"
#define SHM_INIT 0x333
#define SEM_INIT 0x111
#define Q_KEY 0x122
#define HOST_DIR_SIZE 15
#define HOST_SERVICE_SIZE 5
#define FIFO_NAME_LEN 20
#define CONN_TYPE_SIZE 3
#define USER_NAME_LEN 20
#define TYPE_LEN 5
#define ROOM_NAME_LEN 20
#define INIT_SUCCES "1"
#define INIT_FAILURE "0"
#define BLOCK 0
#define NON_BLOCK 1
#define PID_LEN 8

/* ------------------------------------------------------------------------- */
/* -------------------- Funciones Auxiliares ------------------------------- */
/* ------------------------------------------------------------------------- */

typedef struct genHostT{
    char user_name[USER_NAME_LEN+1];
    /* TCP */
    char host_dir[HOST_DIR_SIZE+1];
    char service[HOST_SERVICE_SIZE+1];
    /* MSGQ */
    int q_key;
    /* FIFO */
    char fifo_name[FIFO_NAME_LEN];
    /* SHM */
    int shm_id;
    int sem_id;
} genHostT;

/* Estructura para MSGQ */
struct q_entry {
    long mpriority;
    char text[255];
}q_entry;

/* ------------------------------------------------------------------------- */
/* -------------------------- Prototipos ----------------------------------- */
/* ------------------------------------------------------------------------- */

int validArgs (int argc, char * type);

int validType (char * type);

int getLine (char * line, int linelen, FILE * stream);

int writen(int fd, const void *vptr, size_t n);

int readn(int fd, void *vptr, size_t n);

int passiveTCP(const char *service, int qlen, char * ip);

int passivesock(const char *service, const char *transport, int qlen, char * listen_ip);

int my_max (int a, int b);

void putZeros (char * arr, int len);

#endif /*SHARED_H_*/
